package com.party.pay;

/**
 * @author: zhaoyongke
 * @create: 2025-09-01 15:16
 * @description: XunayRefundController
 */
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/api/xunay/refund")
public class XunayRefundController {
    @Autowired
    private XunayRefundService refundService;

    /**
     * 退款接口（供业务系统调用）
     *
     * @param mchOrderNo   原商户订单号
     * @param mchRefundNo  商户退款单号
     * @param refundAmount 退款金额（分）
     * @param reason       退款原因
     * @param notifyUrl    退款通知地址（可选）
     * @return 退款结果
     */
    @PostMapping("/apply")
    public ResponseEntity<XunayRefundResponse> applyRefund(
            @RequestParam String mchOrderNo,
            @RequestParam String mchRefundNo,
            @RequestParam int refundAmount,
            @RequestParam String reason,
            @RequestParam(required = false) String notifyUrl) throws IOException {

        XunayRefundResponse response = refundService.applyRefund(
                mchOrderNo, mchRefundNo, refundAmount, reason);
        return ResponseEntity.ok(response);
    }

}

